package com.lris.controller;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil;
import com.lris.constant.MessageConstant;
import com.lris.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 聊天接口
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@Tag(name = "即时通讯管理")
@RequestMapping("/socket")
public class SocketController {

    /**
     * 获取通道
     *
     * @return 通道id
     */
    @PostMapping("/getId")
    @Operation(summary = "获取通道id")
    public Result getChainId() {
        try {
            log.info(StpUtil.getLoginId().toString()+"拿到通道id");
//            获取到信道
            log.info((String) StpUtil.getLoginId());
            return Result.success(StpUtil.getLoginId());

        } catch (NotLoginException e) {
            log.info("未登录");
            return Result.error(MessageConstant.UNKNOWN_ERROR);
        }

    }
}
